package com.delivery.www.service.ServiceImpl;

import com.delivery.www.dao.BanDao;
import com.delivery.www.dao.DaoImpl.BanDaoImpl;
import com.delivery.www.po.Ban;
import com.delivery.www.po.Store;
import com.delivery.www.service.BanService;
import com.delivery.www.service.StoreService;

import java.util.List;

/**
 * @author 12970
 */
public class BanServiceImpl implements BanService {
    private final BanDao banDao = new BanDaoImpl();

    @Override
    public boolean doBan(int userId) {
        if (userId > 0) {
            StoreService storeService = new StoreServiceImpl();
            Store store = storeService.getOwnStore(userId);
            if (store != null) {
                storeService.modifyStatus(store.getStoreId(), 0);
            }
            return banDao.doBan(userId) > 0;
        } else {
            return false;
        }
    }

    @Override
    public List<Ban> getBan() {
        return banDao.getBan();
    }

    @Override
    public boolean cancelBan(int userId) {
        if (userId > 0) {
            return banDao.cancelBan(userId) > 0;
        } else {
            return false;
        }
    }

    @Override
    public Ban get(int userId) {
        if (userId > 0) {
            return banDao.get(userId);
        } else {
            return null;
        }
    }

    @Override
    public String judge(int userId) {
        if (userId <= 0) {
            return null;
        } else {
            List<Ban> bans = getBan();
            for (Ban ban : bans) {
                if (ban.getUserId() == userId) {
                    return "exist";
                }
            }
        }
        return null;
    }
}
